<?php if (!defined ('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * 公告，新闻
 * @author chenhuan
 *
 */
class Article extends CI_Controller {

    function index ($url) {
        $this->load->model ('site_model');
        $this->load->model ('article_model');

        $site_list = $this->site_model->get_site_url_news ();
        $url = isset($url) ? $url : 'gonggao';
        $site = $this->site_model->get_site_one (array ('url' => $url));

        //接收参数
        $per_page = $this->input->get ('per_page') ? $this->input->get ('per_page') : 0;
        $txt = trim ($this->input->get ('txt'));
        $data = array ();

        $data['where']['txt'] = $txt;
        $data['page_size'] = ARTICLE_LIST_PAGE_SIZE;
        $data['page_start'] = (int)$per_page;


        $data['where']['nid'] = $site['id'];
        $data['select'] = 1;


        $vdata = $this->article_model->get_article_list ($data);
        $vdata['title'] = $site['title'] . CON_KEYWORDS;
        $vdata['nid'] = $site['id'];

        $vdata['url'] = $url;
        $vdata['txt'] = $txt;


        $vdata['site'] = $site;
        $vdata['site_list'] = $site_list;

        //分页
        $this->load->library ('pagination');
        $config['base_url'] = "/article/index/$url.html?txt=" . $txt;
        $config['total_rows'] = $vdata['article_count'];
        $config['per_page'] = ARTICLE_LIST_PAGE_SIZE;
        $this->pagination->initialize ($config);

        $vdata['atype'] = 'article';

        $vdata['fAction'] = "/article/index/$url.html";

        $this->load->view ('site/news_list', $vdata);

    }

    function view ($article_id) {
        $this->load->model ('site_model');
        $site_list = $this->site_model->get_site_url_news ();

        $this->load->model ('article_model');
        $article = $this->article_model->get_article_obj ($article_id);

        $vdata['site'] = $this->site_model->get_site_obj ($article['nid']);

        $vdata['article'] = $article;
        $vdata['site_list'] = $site_list;
        $vdata['title'] = $article['title'] . ' - ' . CON_KEYWORDS;
        $vdata['atype'] = 'article';
        $this->load->view ("site/news", $vdata);
    }


    function alist ($nid = 22) {
        //接收参数
        $per_page = $this->input->get ('per_page') ? $this->input->get ('per_page') : 0;
        $title = $this->input->get ('title');
        $txt = $this->input->get ('txt');

        $data = array ();
        $data['where']['nid'] = $nid;
        $data['where']['txt'] = $txt;
        $data['page_size'] = ARTICLE_LIST_PAGE_SIZE;
        $data['page_start'] = (int)$per_page;
        $data['select'] = 1;
        $this->load->model ('article_model');
        $vdata = $this->article_model->get_article_list ($data);

        //分页
        $this->load->library ('pagination');
        $config['base_url'] = "/article/alist/$nid.html?txt=" . $txt;
        $config['total_rows'] = $vdata['article_count'];
        $config['per_page'] = ARTICLE_LIST_PAGE_SIZE;
        $this->pagination->initialize ($config);

        $vdata['title'] = $title . CON_KEYWORDS;
        $vdata['txt'] = $txt;
        $vdata['nid'] = $nid;
        $this->load->view ('news_list', $vdata);
    }


    function salong ($nid = 1) {
        //接收参数
        $per_page = $this->input->get ('per_page') ? $this->input->get ('per_page') : 0;

        $data = array ();
        $data['where']['nid'] = $nid;
        $data['page_size'] = ARTICLE_LIST_PAGE_SIZE;
        $data['page_start'] = (int)$per_page;
        $data['select'] = 1;
        $this->load->model ('article_model');
        $vdata = $this->article_model->get_article_list ($data);

        //分页
        $this->load->library ('pagination');
        $config['base_url'] = "/article/salong/$nid.html?";
        $config['total_rows'] = $vdata['article_count'];
        $config['per_page'] = ARTICLE_LIST_PAGE_SIZE;
        $this->pagination->initialize ($config);

        $vdata['per_page'] = $data['page_start'];
        $vdata['nid'] = $nid;
        if ($nid == 1) {
            $vdata['title'] = '股票天地 - ' . CON_KEYWORDS;
        } elseif ($nid == 1) {
            $vdata['title'] = '基金天地 - ' . CON_KEYWORDS;
        } else {
            $vdata['title'] = '保险天地 - ' . CON_KEYWORDS;
        }
        $this->load->view ('/salong_list', $vdata);
    }

    function sview ($article_id) {
        $this->load->model ('article_model');
        $article = $this->article_model->get_article_obj ($article_id);
        $vdata['article'] = $article;
        $vdata['title'] = $article['title'] . ' - ' . CON_KEYWORDS;
        $this->load->view ("salong", $vdata);
    }

    function licheng () {
        $vdata['title'] = '发展历程 - ' . CON_KEYWORDS;
        $this->load->view ("licheng", $vdata);
    }

    function meiti () {
        //接收参数
        $per_page = $this->input->get ('per_page') ? $this->input->get ('per_page') : 0;
        //$title 				= $this->input->get('title');

        $data = array ();
        $data['where']['type'] = 2;
        $data['page_size'] = ARTICLE_LIST_PAGE_SIZE;
        $data['page_start'] = (int)$per_page;
        $this->load->model ('Meiti_model');
        $vdata = $this->Meiti_model->get_list ($data);

        //分页
        $this->load->library ('pagination');
        $config['base_url'] = "/article/meiti?";
        $config['total_rows'] = $vdata['count'];
        $config['per_page'] = ARTICLE_LIST_PAGE_SIZE;
        $this->pagination->initialize ($config);
        $vdata['type'] = 2;
        $this->load->view ('meiti_list', $vdata);
    }

    function yeji () {
        //接收参数
        $per_page = $this->input->get ('per_page') ? $this->input->get ('per_page') : 0;
        //$title 				= $this->input->get('title');

        $data = array ();
        $data['where']['type'] = 1;
        $data['page_size'] = ARTICLE_LIST_PAGE_SIZE;
        $data['page_start'] = (int)$per_page;
        $this->load->model ('Meiti_model');
        $vdata = $this->Meiti_model->get_list ($data);

        //分页
        $this->load->library ('pagination');
        $config['base_url'] = "/article/yeji?";
        $config['total_rows'] = $vdata['count'];
        $config['per_page'] = ARTICLE_LIST_PAGE_SIZE;
        $this->pagination->initialize ($config);
        $vdata['type'] = 1;
        $this->load->view ('yeji_list', $vdata);
    }
}
